package com.bosicloud.cmb.ibp.api.manager.service;

import com.bosicloud.cmb.ibp.api.manager.commom.model.*;
import com.bosicloud.cmb.ibp.api.manager.commom.vo.*;
import com.bosicloud.cmb.ibp.commom.dto.Pagination;

import java.util.List;
import java.util.Optional;

/**
 * API Manager 服务
 *
 * @author Jack Peng / ziliang.peng@bosicloud.com
 */
public interface ApimgmtService {

    /**
     * 所有分类信息
     *
     * @return
     */
    List<IbpApiCategory> allCategory();

    /**
     * 分页获取API列表
     *
     * @param currentPage        当前页码
     * @param pageSize           每页显示条数
     * @param categoryIdOptional 分类ID
     * @return
     */
    Pagination<IbpApi> pagingApi(Integer currentPage, Integer pageSize,
                                 Optional<Integer> categoryIdOptional);

    /**
     * 搜索API
     *
     * @param currentPage        当前页码
     * @param pageSize           每页显示条数
     * @param categoryIdOptional 分类ID
     * @param searchTextOptional 搜索内容
     * @return
     */
    Pagination<IbpApiVO> searchApi(Integer currentPage, Integer pageSize,
                                   Optional<Integer> categoryIdOptional,
                                   Optional<String> searchTextOptional);

    IbpApiVO searchApiDetailById(Integer apiId);

    /**
     * 添加Api
     *
     * @param ibpApi
     * @return Integer
     */
    Integer insertIbpApi(IbpApi ibpApi);


    /**
     * 添加ApiDocs
     *
     * @param ibpApiDocs
     * @return Integer
     */
    Integer insertIbpApidocs(IbpApiDocs ibpApiDocs);


    /**
     * 添加IbpApiDocParams
     *
     * @param apiDocParamsList
     * @return
     */
    Integer insertIbpApiDocParams(List<IbpApiDocParams> apiDocParamsList);

    /**
     * 查询API方法列表
     *
     * @param apiId apiId
     * @return List<ApiMethodListVO>
     */
    List<ApiMethodListVO> searchApiMethodListByApiId(Integer apiId);

    /**
     * 根据docsId查询ApiDocs信息
     *
     * @param docsId docsId
     * @return IbpApiDocs
     */
    IbpApiDocs searchApiDocsInfoById(Integer docsId);


    /**
     * 根据docsId查询参数列表
     *
     * @param docsId docsId
     * @return List<IbpApiDocParams>
     */
    List<IbpApiDocParams> searchParamsListByDocsId(Integer docsId);

    /**
     * 执行添加API相关处理逻辑
     *
     * @param ibpApi ibpApi
     * @return String
     */
    String performAddApiLogic(IbpApi ibpApi);

    /**
     * 根据docsId获取方法详细信息
     *
     * @param docsId docsId
     * @return MethodInfoVO
     */
    MethodInfoVO searchApiMethodInfoByDocsId(Integer docsId);

    /**
     * 根据apiId查询ApiDocs信息
     *
     * @param apiId apiId
     * @return List<IbpApiDocs>
     */
    List<IbpApiDocs> searchApiDocsListByApiId(Integer apiId);

    /**
     * 更新API中方法的详情信息
     *
     * @param methodInfoVO API中方法详情信息
     * @return Integer
     */
    Integer updateApiMethodInfo(MethodInfoVO methodInfoVO);


    /**
     * 更新API状态和apiKeyId
     *
     * @param ibpApi
     * @return Integer
     */
    Integer updateIbpApi(IbpApi ibpApi);

    /**
     * 添加insertIbpApiAwsFailtMsg
     *
     * @param apiAwsFailtMsg
     * @return
     */
    Integer insertIbpApiAwsFailtMsg(IbpApiAwsFailtMsg apiAwsFailtMsg);


    /**
     * 部署API
     *
     * @param deployApiParamVO
     * @return
     */
    String deployApi(DeployApiParamVO deployApiParamVO);

    /**
     * 获取当前环境
     *
     * @param apiId
     * @return
     */

    String getApiNextStatus(Integer apiId);

    /**
     * 添加ibpApiStage
     *
     * @param ibpApiStage
     * @return
     */
    Integer insertIbpApiStage(IbpApiStage ibpApiStage);


    /**
     * 查询开发者api列表
     *
     * @param currentPage 当前页码
     * @param pageSize    每页显示条数
     * @param userId      当前登录用户ID
     * @return
     */
    Pagination<IbpApiVO> searchApiDeveloperList(Integer currentPage, Integer pageSize, Integer userId);


    /**
     * 订阅api
     *
     * @param subscribeApiParamVO
     * @return
     */
    String subscribeApi(SubscribeApiParamVO subscribeApiParamVO);

    /**
     * 取消订阅api
     *
     * @param subscribeApiParamVO
     * @return
     */
    String unSubscribeApi(SubscribeApiParamVO subscribeApiParamVO);

    /**
     * 删除API
     *
     * @param deleteApiParamVO
     * @return
     */
    String deleteApi(DeleteApiParamVO deleteApiParamVO);


    /**
     * 保存订阅API
     *
     * @param ibpUserConsumerApi
     * @return
     */
    Integer insertIbpUserConsumerApi(IbpUserConsumerApi ibpUserConsumerApi);

    /**
     * 查询订阅API
     *
     * @param apiId  apiId
     * @param userId userId
     * @return
     */
    IbpUserConsumerApi searchIbpUserConsumerApi(Integer apiId, Integer userId);

    /**
     * 根据apiId删除IbpApi
     *
     * @param apiId
     * @return Integer
     */
    Integer deleteIbpApiByApiId(Integer apiId);

    /**
     * 根据apiId删除IbpApiDocs
     *
     * @param apiId
     * @return Integer
     */
    Integer deleteIbpApiDocsByApiId(Integer apiId);

    /**
     * 根据apiId删除IbpApiDocParams
     *
     * @param apiId
     * @return Integer
     */
    Integer deleteIbpApiDocParamsByApiId(Integer apiId);


    Pagination<SubscribeApiListVO> subscribeApiList(Integer currentPage, Integer pageSize, Integer userId);


    Boolean checkSubscribeIsAvailable(Integer apiId, Integer userId);

    IbpApiUsagePlan searchUsagePlanInfo(Integer apiId, String env);

    Integer insertIbpApiUsagePlan(IbpApiUsagePlan usagePlan);

    /**
     * 删除订阅
     *
     * @param apiId  apiId
     * @param userId userId
     * @return Integer
     */
    Integer deleteConsumerApi(Integer apiId, Integer userId);

    Integer updateConsumerApi(IbpUserConsumerApi ibpUserConsumerApi);


    /**
     * 根据apiId查询usagePlan
     *
     * @param apiId apiId
     * @return List<IbpApiUsagePlan>
     */
    List<IbpApiUsagePlan> searchUsagePlanListByApiId(Integer apiId);

    IbpApiAwsFailtMsg searchFailMsg(Integer apiId, String bizType, String context);

    /**
     * 根据userId查询用户key列表
     *
     * @param userId apiId
     * @return List<IbpUserApiKeyVO>
     */
    List<IbpUserApiKeyVO> searchUserApiKeyListByUserId(Integer userId);

    Integer updateIbpApiStage(IbpApiStage ibpApiStage);

    /**
     * 是否公开API
     *
     * @param apiId apiId
     * @return String
     */
    String isPublicApi(Integer apiId);

    List<IbpApi> searchApiListFor(IbpApi ibpApi);


    /**
     * 根据docsId获取返回结果码
     *
     * @param docsId docsId
     * @return List<IbpApiDocResponseMgs>
     */
    List<IbpApiDocResponseMgs> searchApiDocResponseMgsByDocsId(Integer docsId);


    /**
     * 根据Id获取返回结果码
     *
     * @param id id
     * @return IbpApiDocResponseMgs
     */
     IbpApiDocResponseMgs  searchApiDocResponseMgsById(Integer id);

    /**
     * 根据docsId获取返回结果头列表
     *
     * @param responseMsgId responseMsgId
     * @return  List<IbpApiDocResponseHeaders>
     */
    List<IbpApiDocResponseHeaders> searchApiDocResponseHeadersByResponseMsgId(Integer responseMsgId);

}
